﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Text.RegularExpressions;
using System.IO;
using System.Diagnostics;
using System.Globalization;
using CommonHelper;

namespace SQLIOSimParser
{
    public class SQLIOSimParserWorker
    {
        #region SummaryFileInformation
        Regex regexBeginSummary = new Regex(@"Final Summary for file (?<FileName>[^*]+)", RegexOptions.Compiled);
        Regex regexFileAttributes = new Regex(@"File Attributes: Compression = (?<Compression>[^,]*), Encryption = (?<Encryption>[^,]*), Sparse = (?<Sparse>[^w|\r|\n]*)", RegexOptions.Compiled);
        Regex regexIOInformation = new Regex(@"Target IO Duration \(ms\) = (?<TargetIODuration_ms>[^,]+), Running Average IO Duration \(ms\) = (?<RunningAverageIODuration_ms>[^,]+), Number of times IO throttled = (?<NumberOfTimesIOThrottled>[^,]+), IO request blocks = (?<IORequestBlocks>[^,|\r|\n]+)", RegexOptions.Compiled);
        Regex regexReadWriteInformation = new Regex(@"Reads = (?<Reads>[^,]+), Scatter Reads = (?<ScatterReads>[^,]+), Writes = (?<Writes>[^,]+), Gather Writes = (?<GatherWrites>[^,]+), Total IO Time \(ms\) = (?<TotalIOTime_ms>[^,|\r|\n]+)", RegexOptions.Compiled);

        Regex regexDriveLevel_1 = new Regex(@"DRIVE LEVEL: Sector size = (?<SectorSize>[^,]+), Cylinders = (?<Cylinders>[^,]+), Media type = (?<MediaType>[^,]+), Sectors per track = (?<SectorPerTrack>[^,]+), Tracks per Cylinders = (?<TracksPerCylinder>[^,]+)", RegexOptions.Compiled);
        Regex regexDriveLevel_2 = new Regex(@"DRIVE LEVEL: Read cache enabled = (?<ReadCacheEnabled>\w+), Write cache enabled = (?<WriteCacheEnabled>\w+)", RegexOptions.Compiled);
        Regex regexDriveLevel_3 = new Regex(@"DRIVE LEVEL: Read count = (?<ReadCount>[^,]*), Read time = (?<ReadTime>[^,]*), Write count = (?<WriteCount>[^,]*), Write time = (?<WriteTime_ms>[^,]*), Idle time = (?<IdleTime_ms>[^,]*), Bytes read = (?<BytesRead>[^,]*), Bytes written = (?<BytesWritten>[^,]*), Split IO Count = (?<SplitIOCount>[^,]*), Storage number = (?<StorageNumber>[^,]*), Storage manager name = (?<StorageManager>[^,]*)", RegexOptions.Compiled);
        
        #endregion SummaryFileInformation
        
        #region RegExInformation
        Regex regexTestVersion = new Regex(@"Simulator Stress Test Version (?<TestVersion>[0-9|\.]+)", RegexOptions.Compiled);
        Regex regexFiles = new Regex(@"Config file (?<IniFile>[\w|\.|:|\\|\s]+), error log (?<LogFile>[\w|\.|:|\\|\s]+)", RegexOptions.Compiled);
        Regex regexServerSettings = new Regex(@"CPUCount = (?<CPUCount>\w+), Affinity = (?<Affinity>\w+), IOAffinity = (?<IOAffinity>\w+), MaxMemory = (?<MaxMemory_MB>[\w]+) MB, StopOnError = (?<StopOnError>\w+), TestCycles = (?<TestCycles>\w+), TestCycleDuration = (?<TestCycleDuration_s>[\w]+) s, CacheHitRatio = (?<CacheHitRatio_pct>[\w]+)", RegexOptions.Compiled);
        Regex regexBuffers = new Regex(@"Created buffer pool. Size=(?<PoolSize_MB>\w+) MB, buffers (?<Buffers>\w+), locked pages (?<LockedPagesSetting>\w+).", RegexOptions.Compiled);

        Regex regexTestIterationNumber = new Regex(@"Performing Full Test iteration #(?<IterationNo>\w+)", RegexOptions.Compiled);
        Regex regexTestBufferScatter = new Regex(@"NoBuffering = (?<NoBuffering>\w+), WriteThrough = (?<WriteThrough>\w+), UseScatterGather = (?<UseScatterGather>\w+), ForceReadAhead = (?<ForceReadAhead>\w+), MaxOutstandingIO = (?<MaxOutstandingIO>\w+), TargetIODuration = (?<TargetIODuration_ms>\w+)", RegexOptions.Compiled);
        Regex regexTestFileInfo = new Regex(@"AllowIOBursts = (?<AllowIOBursts>\w+), DeleteFilesAtStartup = (?<DeletFilesAtStartup>\w+), DeleteFilesAtShutdown = (?<DeleteFilesAtShutdown>\w+), StampFiles = (?<StampFiles>\w+)", RegexOptions.Compiled);

        Regex regexTestUserSettings_1 = new Regex(@"RandomUser: UserCount = (?<RandomUserUserCount>\w+), JumpToNewRegionPercentage = (?<RandomUserJumpToNewRegion_pct>[\w|.]+)%, MinIOChainLength = (?<RandomUserMinIOChainLength>\w+), MaxIOChainLength = (?<RandomUserMaxIOChainLength>\w+), RandomUserReadWriteRatio = (?<RandomUserReadWriteRatio_pct>[\w]+)", RegexOptions.Compiled);
        Regex regexTestUserSettings_2 = new Regex(@"RandomUser: MinLogPerBuffer = (?<RandomUserMinLogPerBuffer>\w+), MaxLogPerBuffer = (?<RandomUserMaxLogPerBuffer>\w+), RollbackChance = (?<RandomUserRollbackChance_pct>[\w|\.|]+)%, SleepAfter = (?<RandomUserSleepAfter_ms>[\w]+) ms, YieldPercentage = (?<RandomUserYieldPercentage_pct>[\w|\.|]+)%", RegexOptions.Compiled);
        Regex regexTestAuditUser = new Regex(@"AuditUser: UserCount = (?<AuditUserUserCount>\w+), BuffersValidated = (?<AuditUserBuffersValidated>\w+), DelayAfterCycles = (?<AuditUserDelayAfterCycles>\w+), AuditDelay = (?<AuditUserAuditDelay_ms>[\w]+) ms", RegexOptions.Compiled);
        Regex regexBulkUpdateUser = new Regex(@"BulkUpdateUser: UserCount = (?<BulkUserUserCount>\w+), BuffersBUMin = (?<BulkUserBuffersMin>\w+), BuffersBUMax = (?<BulkUserBuffersMax>\w+), DelayAfterCycles = (?<BulkUserDelayAfterCycles>\w+), BUDelay = (?<BulkUserDelay_ms>[\w]+) ms", RegexOptions.Compiled);
        Regex regexTestShrinkUser = new Regex(@"ShrinkUser: MinShrinkInterval = (?<ShrinkUserMinShrinkInterval_s>[\w]+) s, MaxShrinkInterval = (?<ShrinkUserMaxShrinkInterval_s>[\w]+) s, MinExtends = (?<ShrinkUserMinExtends>\w+), MaxExtends = (?<ShrinkUserMaxExtends>\w+)", RegexOptions.Compiled);
        Regex regexReadAhead = new Regex(@"ReadAheadUser: UserCount = (?<ReadAheadUserCount>\w+), BuffersRAMin = (?<ReadAheadBuffersMin>\w+), BuffersRAMax = (?<ReadAheadBuffersMax>\w+), DelayAfterCycles = (?<ReadAheadDelayAfterCycles>\w+), RADelay = (?<ReadAheadDelay_ms>\w+) ms", RegexOptions.Compiled);

        Regex regexTestEndTest = new Regex(@"Simulator Stress Test Attempt Complete", RegexOptions.Compiled);

        Regex regexTestFileInfo_2 = new Regex(@"File #\w+ (?<FileName>[\w|\.|\s|:|\\]+) InitialSize", RegexOptions.Compiled);
        #endregion RegExInformation
        
        #region DatetTimeFormats
        string[] formats = {"M/d/yyyy h:mm:ss tt", "M/d/yyyy h:mm tt", 
                                           "MM/dd/yyyy hh:mm:ss", "M/d/yyyy h:mm:ss", 
                                           "M/d/yyyy hh:mm tt", "M/d/yyyy hh tt", 
                                           "M/d/yyyy h:mm", "M/d/yyyy h:mm", 
                                           "MM/dd/yyyy hh:mm", "M/dd/yyyy hh:mm",
                                           "M/d/yy h:mm:ss tt", "M/d/yy h:mm tt", 
                                           "MM/dd/yy hh:mm:ss", "M/d/yy h:mm:ss", 
                                           "M/d/yy hh:mm tt", "M/d/yy hh tt", 
                                           "M/d/yy h:mm", "M/d/yy h:mm", 
                                           "MM/dd/yy hh:mm", "M/dd/yy hh:mm",
                                       
                                            "M/d/yyyy H:mm:ss tt", "M/d/yyyy H:mm tt", 
                                           "MM/dd/yyyy HH:mm:ss", "M/d/yyyy H:mm:ss", 
                                           "M/d/yyyy HH:mm tt", "M/d/yyyy HH tt", 
                                           "M/d/yyyy H:mm", "M/d/yyyy H:mm", 
                                           "MM/dd/yyyy HH:mm", "M/dd/yyyy HH:mm",
                                           "M/d/yy H:mm:ss tt", "M/d/yy H:mm tt", 
                                           "MM/dd/yy HH:mm:ss", "M/d/yy H:mm:ss", 
                                           "M/d/yy hh:mm tt", "M/d/yy HH tt", 
                                           "M/d/yy H:mm", "M/d/yy H:mm", 
                                           "MM/dd/yy HH:mm", "M/dd/yy HH:mm"};
        #endregion DatetTimeFormats

        #region DriveInformationDefinition

        private const string CONST_RESULTTABLE_TESTID = "TestId";        

        private const string CONST_RESULTTABLE_FILENAME = "FileName";

        private const string CONST_RESULTTABLE_COMPRESSION = "Compression";
        private const string CONST_RESULTTABLE_ENCRYPTION = "Encryption";
        private const string CONST_RESULTTABLE_SPARSE = "Sparse";
        
        private const string CONST_RESULTTABLE_RUNNINGAVERAGEIODURATION_MS = "RunningAverageIODuration_ms";
        private const string CONST_RESULTTABLE_NUMBEROFTIMESIOTHROTTLED = "NumberOfTimesIOThrottled";
        private const string CONST_RESULTTABLE_IOREQUESTBLOCKS = "IORequestBlocks";

        private const string CONST_RESULTTABLE_READS = "Reads";
        private const string CONST_RESULTTABLE_SCATTERREADS = "ScatterReads";
        private const string CONST_RESULTTABLE_WRITES = "Writes";
        private const string CONST_RESULTTABLE_GATHERWRITES = "GatherWrites";
        private const string CONST_RESULTTABLE_TOTALIOTIME_MS = "TotalIOTime_ms";

        private const string CONST_RESULTTABLE_SECTORSIZE = "SectorSize";
        private const string CONST_RESULTTABLE_CYLINDERS = "Cylinders";
        private const string CONST_RESULTTABLE_MEDIATYPE = "MediaType";
        private const string CONST_RESULTTABLE_SECTORPERTRACK = "SectorPerTrack";
        private const string CONST_RESULTTABLE_TRACKSPERCYLINDER = "TracksPerCylinder";

        private const string CONST_RESULTTABLE_READCACHEENABLED = "ReadCacheEnabled";
        private const string CONST_RESULTTABLE_WRITECACHEENABLED = "WriteCacheEnabled";

        private const string CONST_RESULTTABLE_READCOUNT = "ReadCount";
        private const string CONST_RESULTTABLE_READTIME = "ReadTime";
        private const string CONST_RESULTTABLE_WRITECOUNT = "WriteCount";
        private const string CONST_RESULTTABLE_WRITETIME_MS = "WriteTime_ms";
        private const string CONST_RESULTTABLE_IDLETIME_MS = "IdleTime_ms";
        private const string CONST_RESULTTABLE_BYTESREAD = "BytesRead";
        private const string CONST_RESULTTABLE_BYTESWRITTEN = "BytesWritten";
        private const string CONST_RESULTTABLE_SPLITIOCOUNT = "SplitIOCount";
        private const string CONST_RESULTTABLE_STORAGENUMBER = "StorageNumber";
        private const string CONST_RESULTTABLE_STORAGEMANAGER = "StorageManager";

        private const string CONST_RESULTTABLE_ROWID = "RowId";
        private const string CONST_RESULTTABLE_DRIVELETTER = "DriveLetter";
        private const string CONST_RESULTTABLE_TESTTIME = "TestTime";


        #endregion DriveInformationDefinition

        #region TestColumnDefinition

        private const string CONST_RESULTTABLE_TESTVERSION = "TestVersion";
        private const string CONST_RESULTTABLE_CONFIGFILE = "IniFile";
        private const string CONST_RESULTTABLE_ERRORLOG = "LogFile";
        private const string CONST_RESULTTABLE_CPUCOUNT = "CPUCount";
        private const string CONST_RESULTTABLE_AFFINITY = "Affinity";
        private const string CONST_RESULTTABLE_IOAFFINITY  = "IOAffinity";
        private const string CONST_RESULTTABLE_MAXMEMORY_MB = "MaxMemory_MB";
        private const string CONST_RESULTTABLE_STOPONERROR = "StopOnError";
        private const string CONST_RESULTTABLE_TESTCYCLES = "TestCycles";
        private const string CONST_RESULTTABLE_TESTCYCLEDURN_S = "TestCycleDuration_s";
        private const string CONST_RESULTTABLE_CACHEHITRATIO_PCT = "CacheHitRatio_pct";
        private const string CONST_RESULTTABLE_LOCKEDPAGES = "LockedPages";
        private const string CONST_RESULTTABLE_POOLSIZE_MB = "PoolSize_MB";
        private const string CONST_RESULTTABLE_BUFFERS = "Buffers";

        private const string CONST_RESULTTABLE_ITERATIONNUMBER = "IterationNo";
        private const string CONST_RESULTTABLE_TESTNAME = "TestName";

        private const string CONST_RESULTTABLE_NOBUFFERING = "NoBuffering";
        private const string CONST_RESULTTABLE_WRITETHROUGH = "WriteThrough";
        private const string CONST_RESULTTABLE_USESCATTERGATHER = "UseScatterGather";
        private const string CONST_RESULTTABLE_FORCEREADAHEAD = "ForceReadAhead";
        private const string CONST_RESULTTABLE_MAXOUTSTANDINGIO = "MaxOutstandingIO";
        private const string CONST_RESULTTABLE_TARGETIODURATION_MS = "TargetIODuration_ms";
        private const string CONST_RESULTTABLE_ALLOWIOBURSTS = "AllowIOBursts";
        private const string CONST_RESULTTABLE_DELETEFILESATSTARTUP = "DeleteFilesAtStartup";
        private const string CONST_RESULTTABLE_DELETEFILESATSHUTDOWN = "DeleteFilesAtShutdown";
        private const string CONST_RESULTTABLE_STAMPFILES = "StampFiles";
        private const string CONST_RESULTTABLE_RANDOMUSERCOUNT = "RandomUserUserCount";
        private const string CONST_RESULTTABLE_RANDOMUSERJUMPTONEWREGION_PCT = "RandomUserJumpToNewRegion_pct";
        private const string CONST_RESULTTABLE_RANDOMUSERMINIOCHAINLENGTH = "RandomUserMinIOChainLength";
        private const string CONST_RESULTTABLE_RANDOMUSERMAXIOCHAINLENGTH = "RandomUserMaxIOChainLength";
        private const string CONST_RESULTTABLE_RANDOMUSERRANDOMUSERREADWRITERATIO_PCT = "RandomUserReadWriteRatio_pct";
        private const string CONST_RESULTTABLE_RANDOMUSERMINLOGPERBUFFER = "RandomUserMinLogPerBuffer";
        private const string CONST_RESULTTABLE_RANDOMUSERMAXLOGPERBUFFER = "RandomUserMaxLogPerBuffer";
        private const string CONST_RESULTTABLE_RANDOMUSERROLLBACKCHANCE_PCT = "RandomUserRollbackChance_pct";
        private const string CONST_RESULTTABLE_RANDOMUSERSLEEPAFTER_MS = "RandomUserSleepAfter_ms";
        private const string CONST_RESULTTABLE_RANDOMUSERYIELD_PCT = "RandomUserYieldPercentage_pct";

        private const string CONST_RESULTTABLE_AUDITUSERUSERCOUNT = "AuditUserUserCount";
        private const string CONST_RESULTTABLE_AUDITUSERBUFFERSVALIDATED = "AuditUserBuffersValidated";
        private const string CONST_RESULTTABLE_AUDITUSERDELAYAFTERCYCLES = "AuditUserDelayAfterCycles";
        private const string CONST_RESULTTABLE_AUDITUSERAUDITDELAY_MS = "AuditUserAuditDelay_ms";

        private const string CONST_RESULTTABLE_READAHEADUSERCOUNT = "ReadAheadUserCount";
        private const string CONST_RESULTTABLE_READAHEADBUFFERSMIN = "ReadAheadBuffersMin";
        private const string CONST_RESULTTABLE_READAHEADBUFFERSMAX = "ReadAheadBuffersMax";
        private const string CONST_RESULTTABLE_READAHEADDELAYAFTERCYCLES = "ReadAheadDelayAfterCycles";
        private const string CONST_RESULTTABLE_READAHEADDELAY_MS = "ReadAheadDelay_ms";

        private const string CONST_RESULTTABLE_BULKUPDATEUSERCOUNT = "BulkUserUserCount";
        private const string CONST_RESULTTABLE_BULKUSERBUFFERSMIN = "BulkUserBuffersMin";
        private const string CONST_RESULTTABLE_BULKUSERBUFFERSMAX = "BulkUserBuffersMax";
        private const string CONST_RESULTTABLE_BULKUSERDELAYAFTERCYCLES = "BulkUserDelayAfterCycles";
        private const string CONST_RESULTTABLE_BULKUSERDELAY_MS = "BulkUserDelay_ms";

        private const string CONST_RESULTTABLE_SHRINKMINSHRINKINTERVAL_S = "ShrinkUserMinShrinkInterval_s";
        private const string CONST_RESULTTABLE_SHRINKMAXSHRINKINTERVAL_S = "ShrinkUserMaxShrinkInterval_s";
        private const string CONST_RESULTTABLE_SHRINKMINEXTENDS = "ShrinkUserMinExtends";
        private const string CONST_RESULTTABLE_SHRINKMAXEXTENDS = "ShrinkUserMaxExtends";

        #endregion TestColumnDefinition


        private const string CONST_FILECONTENT_EXTENDED_DESCRIPTION = "EXTENDED_DESCRIPTION";

        private const string CONST_MESSAGE_EXPORT_FILE = "The result has been exported to '{0}.'";
        private const string CONST_MESSAGE_FOUND_TESTS = "--> {0} tests were found.";
        private const string CONST_MESSAGE_FOUND_DRIVES = "--> {0} drive information were found.";

        public delegate void HandleMessage(string Message, TraceLevel tracelevel);
        public event HandleMessage HandleMessageEvent;

        DataTable _resultTable;
        DataTable _testInformation;
        DataRow CurrentDriveRow;
        DataRow CurrentTestRow;

        Dictionary<int, Regex> SummaryFileInformationDict;
        Dictionary<int, Regex> RegExInformationDict;

        private int IterationCounter = 0;
        private int GlobalDriveCounter = 0;
        private int LocalDriveCounter = 0;

        private DataSet dsResults;

        public DataTable ResultTable
        {
            get 
            {
                if (_resultTable == null)
                    InitResultTable();

                return _resultTable;
            }
        }

        private void InitResultTable()
        {
            _resultTable = new DataTable("FileDetails");

            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_TESTID, System.Type.GetType("System.Int16")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_ROWID, System.Type.GetType("System.Int16")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_DRIVELETTER, System.Type.GetType("System.String")));

            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_FILENAME, System.Type.GetType("System.String")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_COMPRESSION, System.Type.GetType("System.Boolean")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_ENCRYPTION, System.Type.GetType("System.Boolean")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_SPARSE, System.Type.GetType("System.Boolean")));
         
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_TARGETIODURATION_MS, System.Type.GetType("System.Int64")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_RUNNINGAVERAGEIODURATION_MS, System.Type.GetType("System.Int64")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_NUMBEROFTIMESIOTHROTTLED, System.Type.GetType("System.Int64")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_IOREQUESTBLOCKS, System.Type.GetType("System.Int64")));

            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_READS, System.Type.GetType("System.Int64")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_SCATTERREADS, System.Type.GetType("System.Int64")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_WRITES, System.Type.GetType("System.Int64")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_GATHERWRITES, System.Type.GetType("System.Int64")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_TOTALIOTIME_MS, System.Type.GetType("System.Int64")));

            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_SECTORSIZE, System.Type.GetType("System.Int64")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_CYLINDERS, System.Type.GetType("System.Int64")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_MEDIATYPE, System.Type.GetType("System.Int64")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_SECTORPERTRACK, System.Type.GetType("System.Int64")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_TRACKSPERCYLINDER, System.Type.GetType("System.Int64")));

            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_READCACHEENABLED, System.Type.GetType("System.Boolean")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_WRITECACHEENABLED, System.Type.GetType("System.Boolean")));
            
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_READCOUNT, System.Type.GetType("System.Int64")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_READTIME, System.Type.GetType("System.Int64")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_WRITECOUNT, System.Type.GetType("System.Int64")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_WRITETIME_MS, System.Type.GetType("System.Int64")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_IDLETIME_MS, System.Type.GetType("System.Int64")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_BYTESREAD, System.Type.GetType("System.Int64")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_BYTESWRITTEN, System.Type.GetType("System.Int64")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_SPLITIOCOUNT, System.Type.GetType("System.Int64")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_STORAGENUMBER, System.Type.GetType("System.Int64")));
            _resultTable.Columns.Add(new DataColumn(CONST_RESULTTABLE_STORAGEMANAGER, System.Type.GetType("System.String")));

            _testInformation = new DataTable("TestInformation");

            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_TESTID, System.Type.GetType("System.Int16")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_TESTVERSION, System.Type.GetType("System.String")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_CONFIGFILE, System.Type.GetType("System.String")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_ERRORLOG, System.Type.GetType("System.String")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_CPUCOUNT, System.Type.GetType("System.Int16")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_AFFINITY, System.Type.GetType("System.String")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_IOAFFINITY, System.Type.GetType("System.String")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_MAXMEMORY_MB, System.Type.GetType("System.Int32")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_STOPONERROR, System.Type.GetType("System.Boolean")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_TESTCYCLES, System.Type.GetType("System.String")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_TESTCYCLEDURN_S, System.Type.GetType("System.String")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_CACHEHITRATIO_PCT, System.Type.GetType("System.Int16")));
            
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_POOLSIZE_MB, System.Type.GetType("System.Int32")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_BUFFERS, System.Type.GetType("System.String")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_LOCKEDPAGES, System.Type.GetType("System.Boolean")));

            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_ITERATIONNUMBER, System.Type.GetType("System.Int16")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_TESTNAME, System.Type.GetType("System.String")));
            
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_NOBUFFERING, System.Type.GetType("System.Boolean")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_WRITETHROUGH, System.Type.GetType("System.Boolean")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_USESCATTERGATHER, System.Type.GetType("System.Boolean")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_FORCEREADAHEAD, System.Type.GetType("System.Boolean")));

            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_MAXOUTSTANDINGIO, System.Type.GetType("System.Int32")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_TARGETIODURATION_MS, System.Type.GetType("System.String")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_ALLOWIOBURSTS, System.Type.GetType("System.Boolean")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_DELETEFILESATSTARTUP, System.Type.GetType("System.Boolean")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_DELETEFILESATSHUTDOWN, System.Type.GetType("System.Boolean")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_STAMPFILES, System.Type.GetType("System.Boolean")));

            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_RANDOMUSERCOUNT, System.Type.GetType("System.Int16")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_RANDOMUSERJUMPTONEWREGION_PCT, System.Type.GetType("System.String")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_RANDOMUSERMINIOCHAINLENGTH, System.Type.GetType("System.Int32")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_RANDOMUSERMAXIOCHAINLENGTH, System.Type.GetType("System.Int32")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_RANDOMUSERRANDOMUSERREADWRITERATIO_PCT, System.Type.GetType("System.Int16")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_RANDOMUSERMINLOGPERBUFFER, System.Type.GetType("System.Int16")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_RANDOMUSERMAXLOGPERBUFFER, System.Type.GetType("System.Int16")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_RANDOMUSERROLLBACKCHANCE_PCT, System.Type.GetType("System.String")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_RANDOMUSERSLEEPAFTER_MS, System.Type.GetType("System.String")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_RANDOMUSERYIELD_PCT, System.Type.GetType("System.String")));

            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_AUDITUSERUSERCOUNT, System.Type.GetType("System.Int16")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_AUDITUSERBUFFERSVALIDATED, System.Type.GetType("System.Int32")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_AUDITUSERDELAYAFTERCYCLES, System.Type.GetType("System.Int32")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_AUDITUSERAUDITDELAY_MS, System.Type.GetType("System.Int32")));

            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_READAHEADUSERCOUNT, System.Type.GetType("System.Int16")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_READAHEADBUFFERSMIN, System.Type.GetType("System.Int32")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_READAHEADBUFFERSMAX, System.Type.GetType("System.Int32")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_READAHEADDELAYAFTERCYCLES, System.Type.GetType("System.Int32")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_READAHEADDELAY_MS, System.Type.GetType("System.Int32")));

            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_BULKUPDATEUSERCOUNT, System.Type.GetType("System.Int16")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_BULKUSERBUFFERSMIN, System.Type.GetType("System.Int32")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_BULKUSERBUFFERSMAX, System.Type.GetType("System.Int32")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_BULKUSERDELAYAFTERCYCLES, System.Type.GetType("System.Int32")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_BULKUSERDELAY_MS, System.Type.GetType("System.String")));
            
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_SHRINKMINSHRINKINTERVAL_S, System.Type.GetType("System.String")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_SHRINKMAXSHRINKINTERVAL_S, System.Type.GetType("System.String")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_SHRINKMINEXTENDS, System.Type.GetType("System.Int32")));
            _testInformation.Columns.Add(new DataColumn(CONST_RESULTTABLE_SHRINKMAXEXTENDS, System.Type.GetType("System.Int32")));

//        Test#

            dsResults = new DataSet("Results");
            dsResults.Tables.Add(_testInformation);
            dsResults.Tables.Add(_resultTable);
            dsResults.EnforceConstraints = false;
            dsResults.Relations.Add(new DataRelation("Test_FileInformation", _testInformation.Columns[CONST_RESULTTABLE_TESTID], _resultTable.Columns[CONST_RESULTTABLE_TESTID]));
        }


        public SQLIOSimParserWorker()
        {
            InitResultTable();
            InitRegExCollections();
        }

        #region InitRegExCollections
        private void InitRegExCollections()
        {
            SummaryFileInformationDict = new Dictionary<int, Regex>();

            SummaryFileInformationDict.Add(1, regexBeginSummary);
            SummaryFileInformationDict.Add(2, regexFileAttributes);
            SummaryFileInformationDict.Add(3, regexIOInformation);
            SummaryFileInformationDict.Add(4, regexReadWriteInformation);
            SummaryFileInformationDict.Add(5, regexDriveLevel_1);
            SummaryFileInformationDict.Add(6, regexDriveLevel_2);
            SummaryFileInformationDict.Add(7, regexDriveLevel_3);
            
            RegExInformationDict = new Dictionary<int, Regex>();

            RegExInformationDict.Add(1, regexTestVersion);
            RegExInformationDict.Add(2, regexFiles);
            RegExInformationDict.Add(3, regexServerSettings);
            RegExInformationDict.Add(4, regexBuffers);
            RegExInformationDict.Add(5, regexTestIterationNumber);
            RegExInformationDict.Add(6, regexTestBufferScatter);
            RegExInformationDict.Add(7, regexTestFileInfo);
            RegExInformationDict.Add(8, regexTestUserSettings_1);
            RegExInformationDict.Add(9, regexTestUserSettings_2);
            RegExInformationDict.Add(10, regexTestAuditUser);
            RegExInformationDict.Add(11, regexBulkUpdateUser);
            RegExInformationDict.Add(12, regexTestShrinkUser);
            RegExInformationDict.Add(13, regexTestFileInfo_2);
        }
        #endregion InitRegExCollections


        public DataSet ParseIOSimFile(string SQLIOSimFile)
        {

            if (!File.Exists(SQLIOSimFile))
            {
                HandleMessageEvent(string.Format("Input file '{0}' does not exist or access is denied.", SQLIOSimFile), TraceLevel.Error);
                return null;
            }
            
            DataSet ds = new DataSet();
            ds.ReadXml(SQLIOSimFile);

            foreach (DataRow dr in ds.Tables[0].Rows)
            {

                string CurrentLine = dr[CONST_FILECONTENT_EXTENDED_DESCRIPTION].ToString();
                
                if (!TryParseHeaderInformation(CurrentLine))
                    TryParseFileInformation(CurrentLine);

            }

            HandleMessageEvent(string.Format(CONST_MESSAGE_FOUND_TESTS, IterationCounter), TraceLevel.Info); ;
            HandleMessageEvent(string.Format(CONST_MESSAGE_FOUND_DRIVES, GlobalDriveCounter), TraceLevel.Info); ;

            PostProcessEvent("XMLFileParsed", new string[] { "Interations:" + ds.Tables[0].Rows.Count, "DriveCount:" + ds.Tables[1].Rows.Count });

            return dsResults;
        }

        private bool TryParseFileInformation(string CurrentLine)
        {

            Match match = regexBeginSummary.Match(CurrentLine);
            
            if (match.Success)
            {
                CurrentDriveRow = ResultTable.NewRow();
                LocalDriveCounter++;
                GlobalDriveCounter++;
                CurrentDriveRow[CONST_RESULTTABLE_ROWID] = GlobalDriveCounter;
                CurrentDriveRow[CONST_RESULTTABLE_TESTID] = IterationCounter;
                CurrentDriveRow[CONST_RESULTTABLE_FILENAME] = match.Groups[CONST_RESULTTABLE_FILENAME].Value;
                CurrentDriveRow[CONST_RESULTTABLE_DRIVELETTER] = match.Groups[CONST_RESULTTABLE_FILENAME].Value.Substring(0, 1) + ":";
            }


            if (match.Success)
                return true;

            match = regexFileAttributes.Match(CurrentLine);

            if (match.Success)
            {
                CurrentDriveRow[CONST_RESULTTABLE_COMPRESSION] = match.Groups[CONST_RESULTTABLE_COMPRESSION].Value == "No" ? false : true;
                CurrentDriveRow[CONST_RESULTTABLE_ENCRYPTION] = match.Groups[CONST_RESULTTABLE_ENCRYPTION].Value == "No" ? false : true;
                CurrentDriveRow[CONST_RESULTTABLE_SPARSE] = match.Groups[CONST_RESULTTABLE_SPARSE].Value == "No" ? false : true;
            }

            if (match.Success)
                return true;

            match = regexIOInformation.Match(CurrentLine);

            if (match.Success)
            {
                CurrentDriveRow[CONST_RESULTTABLE_TARGETIODURATION_MS] = match.Groups[CONST_RESULTTABLE_TARGETIODURATION_MS].Value;
                CurrentDriveRow[CONST_RESULTTABLE_RUNNINGAVERAGEIODURATION_MS] = match.Groups[CONST_RESULTTABLE_RUNNINGAVERAGEIODURATION_MS].Value;
                CurrentDriveRow[CONST_RESULTTABLE_NUMBEROFTIMESIOTHROTTLED] = match.Groups[CONST_RESULTTABLE_NUMBEROFTIMESIOTHROTTLED].Value;
                CurrentDriveRow[CONST_RESULTTABLE_IOREQUESTBLOCKS] = match.Groups[CONST_RESULTTABLE_IOREQUESTBLOCKS].Value;
            }


            if (match.Success)
                return true;
            
            match = regexReadWriteInformation.Match(CurrentLine);

            if (match.Success)
            {
                CurrentDriveRow[CONST_RESULTTABLE_READS] = match.Groups[CONST_RESULTTABLE_READS].Value;
                CurrentDriveRow[CONST_RESULTTABLE_SCATTERREADS] = match.Groups[CONST_RESULTTABLE_SCATTERREADS].Value;
                CurrentDriveRow[CONST_RESULTTABLE_WRITES] = match.Groups[CONST_RESULTTABLE_WRITES].Value;
                CurrentDriveRow[CONST_RESULTTABLE_GATHERWRITES] = match.Groups[CONST_RESULTTABLE_GATHERWRITES].Value;
                CurrentDriveRow[CONST_RESULTTABLE_TOTALIOTIME_MS] = match.Groups[CONST_RESULTTABLE_TOTALIOTIME_MS].Value;
            }

            if (match.Success)
                return true;
            
            match = regexDriveLevel_1.Match(CurrentLine);

            if (match.Success)
            {
                CurrentDriveRow[CONST_RESULTTABLE_SECTORSIZE] = match.Groups[CONST_RESULTTABLE_SECTORSIZE].Value;
                CurrentDriveRow[CONST_RESULTTABLE_CYLINDERS] = match.Groups[CONST_RESULTTABLE_CYLINDERS].Value;
                CurrentDriveRow[CONST_RESULTTABLE_MEDIATYPE] = match.Groups[CONST_RESULTTABLE_MEDIATYPE].Value;
                CurrentDriveRow[CONST_RESULTTABLE_SECTORPERTRACK] = match.Groups[CONST_RESULTTABLE_SECTORPERTRACK].Value;
                CurrentDriveRow[CONST_RESULTTABLE_TRACKSPERCYLINDER] = match.Groups[CONST_RESULTTABLE_TRACKSPERCYLINDER].Value;
            }

            if (match.Success)
                return true;
            
            match = regexDriveLevel_2.Match(CurrentLine);

            if (match.Success)
            {
                CurrentDriveRow[CONST_RESULTTABLE_READCACHEENABLED] = match.Groups[CONST_RESULTTABLE_READCACHEENABLED].Value == "No" ? false : true;
                CurrentDriveRow[CONST_RESULTTABLE_WRITECACHEENABLED] = match.Groups[CONST_RESULTTABLE_WRITECACHEENABLED].Value == "No" ? false : true;
            }


            if (match.Success)
                return true;
            
            match = regexDriveLevel_3.Match(CurrentLine);

            if (match.Success)
            {
                CurrentDriveRow[CONST_RESULTTABLE_READCOUNT] = match.Groups[CONST_RESULTTABLE_READCOUNT].Value;
                CurrentDriveRow[CONST_RESULTTABLE_READTIME] = match.Groups[CONST_RESULTTABLE_READTIME].Value;
                CurrentDriveRow[CONST_RESULTTABLE_WRITECOUNT] = match.Groups[CONST_RESULTTABLE_WRITECOUNT].Value;
                CurrentDriveRow[CONST_RESULTTABLE_WRITETIME_MS] = match.Groups[CONST_RESULTTABLE_WRITETIME_MS].Value;
                CurrentDriveRow[CONST_RESULTTABLE_IDLETIME_MS] = match.Groups[CONST_RESULTTABLE_IDLETIME_MS].Value;
                CurrentDriveRow[CONST_RESULTTABLE_BYTESREAD] = match.Groups[CONST_RESULTTABLE_BYTESREAD].Value;
                CurrentDriveRow[CONST_RESULTTABLE_BYTESWRITTEN] = match.Groups[CONST_RESULTTABLE_BYTESWRITTEN].Value;
                CurrentDriveRow[CONST_RESULTTABLE_SPLITIOCOUNT] = match.Groups[CONST_RESULTTABLE_SPLITIOCOUNT].Value;
                CurrentDriveRow[CONST_RESULTTABLE_STORAGENUMBER] = match.Groups[CONST_RESULTTABLE_STORAGENUMBER].Value;
                CurrentDriveRow[CONST_RESULTTABLE_STORAGEMANAGER] = match.Groups[CONST_RESULTTABLE_STORAGEMANAGER].Value;
            }


            if (CurrentDriveRow != null)
            {
                ResultTable.Rows.Add(CurrentDriveRow);
                
                CurrentDriveRow = null;
            }


            if (match.Success)
                return true;
            else return false;

        }

        private bool TryParseHeaderInformation(string CurrentLine)
        {

            Match match;

            match = regexTestVersion.Match(CurrentLine);

            if (match.Success)
            {
                IterationCounter++;
                CurrentTestRow = _testInformation.NewRow();
                CurrentTestRow[CONST_RESULTTABLE_TESTVERSION] = match.Groups[CONST_RESULTTABLE_TESTVERSION].Value;
                CurrentTestRow[CONST_RESULTTABLE_TESTID] = IterationCounter;
            }


            if (match.Success)
                return true;

            match = regexFiles.Match(CurrentLine);

            if (match.Success)
            {
                CurrentTestRow[CONST_RESULTTABLE_CONFIGFILE] = match.Groups[CONST_RESULTTABLE_CONFIGFILE].Value;
                CurrentTestRow[CONST_RESULTTABLE_ERRORLOG] = match.Groups[CONST_RESULTTABLE_ERRORLOG].Value;
            }


            if (match.Success)
                return true;

            match = regexServerSettings.Match(CurrentLine);

            if (match.Success)
            {
                CurrentTestRow[CONST_RESULTTABLE_CPUCOUNT] = match.Groups[CONST_RESULTTABLE_CPUCOUNT].Value;
                CurrentTestRow[CONST_RESULTTABLE_AFFINITY] = match.Groups[CONST_RESULTTABLE_AFFINITY].Value;
                CurrentTestRow[CONST_RESULTTABLE_IOAFFINITY] = match.Groups[CONST_RESULTTABLE_IOAFFINITY].Value;
                CurrentTestRow[CONST_RESULTTABLE_MAXMEMORY_MB] = match.Groups[CONST_RESULTTABLE_MAXMEMORY_MB].Value;
                CurrentTestRow[CONST_RESULTTABLE_STOPONERROR] = match.Groups[CONST_RESULTTABLE_STOPONERROR].Value == "No" ? false : true;
                CurrentTestRow[CONST_RESULTTABLE_TESTCYCLES] = match.Groups[CONST_RESULTTABLE_TESTCYCLES].Value;
                CurrentTestRow[CONST_RESULTTABLE_TESTCYCLEDURN_S] = match.Groups[CONST_RESULTTABLE_TESTCYCLEDURN_S].Value;
                CurrentTestRow[CONST_RESULTTABLE_CACHEHITRATIO_PCT] = match.Groups[CONST_RESULTTABLE_CACHEHITRATIO_PCT].Value;
            }


            if (match.Success)
                return true;

            match = regexBuffers.Match(CurrentLine);

            if (match.Success)
            {
                CurrentTestRow[CONST_RESULTTABLE_POOLSIZE_MB] = match.Groups[CONST_RESULTTABLE_POOLSIZE_MB].Value;
                CurrentTestRow[CONST_RESULTTABLE_BUFFERS] = match.Groups[CONST_RESULTTABLE_BUFFERS].Value;
                CurrentTestRow[CONST_RESULTTABLE_LOCKEDPAGES] = match.Groups[CONST_RESULTTABLE_LOCKEDPAGES].Value == "No" ? false : true;
            }

            if (match.Success)
                return true;

            match = regexTestIterationNumber.Match(CurrentLine);

            if (match.Success)
            {
                CurrentTestRow[CONST_RESULTTABLE_ITERATIONNUMBER] = match.Groups[CONST_RESULTTABLE_ITERATIONNUMBER].Value;
            }


            if (match.Success)
                return true;


            match = regexTestBufferScatter.Match(CurrentLine);

            if (match.Success)
            {
                CurrentTestRow[CONST_RESULTTABLE_NOBUFFERING] = match.Groups[CONST_RESULTTABLE_NOBUFFERING].Value == "No" ? false : true;
                CurrentTestRow[CONST_RESULTTABLE_WRITETHROUGH] = match.Groups[CONST_RESULTTABLE_WRITETHROUGH].Value == "No" ? false : true;
                CurrentTestRow[CONST_RESULTTABLE_USESCATTERGATHER] = match.Groups[CONST_RESULTTABLE_USESCATTERGATHER].Value == "No" ? false : true;
                CurrentTestRow[CONST_RESULTTABLE_FORCEREADAHEAD] = match.Groups[CONST_RESULTTABLE_FORCEREADAHEAD].Value == "No" ? false : true;
                CurrentTestRow[CONST_RESULTTABLE_MAXOUTSTANDINGIO] = match.Groups[CONST_RESULTTABLE_MAXOUTSTANDINGIO].Value;
                CurrentTestRow[CONST_RESULTTABLE_TARGETIODURATION_MS] = match.Groups[CONST_RESULTTABLE_TARGETIODURATION_MS].Value;
            }


            if (match.Success)
                return true;




            match = regexTestFileInfo.Match(CurrentLine);

            if (match.Success)
            {
                CurrentTestRow[CONST_RESULTTABLE_ALLOWIOBURSTS] = match.Groups[CONST_RESULTTABLE_ALLOWIOBURSTS].Value == "No" ? false : true;
                CurrentTestRow[CONST_RESULTTABLE_DELETEFILESATSTARTUP] = match.Groups[CONST_RESULTTABLE_DELETEFILESATSTARTUP].Value == "No" ? false : true;
                CurrentTestRow[CONST_RESULTTABLE_DELETEFILESATSHUTDOWN] = match.Groups[CONST_RESULTTABLE_DELETEFILESATSHUTDOWN].Value == "No" ? false : true;
                CurrentTestRow[CONST_RESULTTABLE_STAMPFILES] = match.Groups[CONST_RESULTTABLE_STAMPFILES].Value == "No" ? false : true;
            }


            if (match.Success)
                return true;


            match = regexTestUserSettings_1.Match(CurrentLine);

            if (match.Success)
            {
                CurrentTestRow[CONST_RESULTTABLE_RANDOMUSERCOUNT] = match.Groups[CONST_RESULTTABLE_RANDOMUSERCOUNT].Value;
                CurrentTestRow[CONST_RESULTTABLE_RANDOMUSERJUMPTONEWREGION_PCT] = match.Groups[CONST_RESULTTABLE_RANDOMUSERJUMPTONEWREGION_PCT].Value;
                CurrentTestRow[CONST_RESULTTABLE_RANDOMUSERMINIOCHAINLENGTH] = match.Groups[CONST_RESULTTABLE_RANDOMUSERMINIOCHAINLENGTH].Value;
                CurrentTestRow[CONST_RESULTTABLE_RANDOMUSERMAXIOCHAINLENGTH] = match.Groups[CONST_RESULTTABLE_RANDOMUSERMAXIOCHAINLENGTH].Value;
                CurrentTestRow[CONST_RESULTTABLE_RANDOMUSERRANDOMUSERREADWRITERATIO_PCT] = match.Groups[CONST_RESULTTABLE_RANDOMUSERRANDOMUSERREADWRITERATIO_PCT].Value;
            }


            if (match.Success)
                return true;

            match = regexTestUserSettings_2.Match(CurrentLine);

            if (match.Success)
            {
                CurrentTestRow[CONST_RESULTTABLE_RANDOMUSERMINLOGPERBUFFER] = match.Groups[CONST_RESULTTABLE_RANDOMUSERMINLOGPERBUFFER].Value;
                CurrentTestRow[CONST_RESULTTABLE_RANDOMUSERMAXLOGPERBUFFER] = match.Groups[CONST_RESULTTABLE_RANDOMUSERMAXLOGPERBUFFER].Value;
                CurrentTestRow[CONST_RESULTTABLE_RANDOMUSERROLLBACKCHANCE_PCT] = match.Groups[CONST_RESULTTABLE_RANDOMUSERROLLBACKCHANCE_PCT].Value;
                CurrentTestRow[CONST_RESULTTABLE_RANDOMUSERSLEEPAFTER_MS] = match.Groups[CONST_RESULTTABLE_RANDOMUSERSLEEPAFTER_MS].Value;
                CurrentTestRow[CONST_RESULTTABLE_RANDOMUSERYIELD_PCT] = match.Groups[CONST_RESULTTABLE_RANDOMUSERYIELD_PCT].Value;
            }


            if (match.Success)
                return true;

            match = regexTestAuditUser.Match(CurrentLine);

            if (match.Success)
            {
                CurrentTestRow[CONST_RESULTTABLE_AUDITUSERUSERCOUNT] = match.Groups[CONST_RESULTTABLE_AUDITUSERUSERCOUNT].Value;
                CurrentTestRow[CONST_RESULTTABLE_AUDITUSERBUFFERSVALIDATED] = match.Groups[CONST_RESULTTABLE_AUDITUSERBUFFERSVALIDATED].Value;
                CurrentTestRow[CONST_RESULTTABLE_AUDITUSERDELAYAFTERCYCLES] = match.Groups[CONST_RESULTTABLE_AUDITUSERDELAYAFTERCYCLES].Value;
                CurrentTestRow[CONST_RESULTTABLE_AUDITUSERAUDITDELAY_MS] = match.Groups[CONST_RESULTTABLE_AUDITUSERAUDITDELAY_MS].Value;
            }


            if (match.Success)
                return true;

            match = regexBulkUpdateUser.Match(CurrentLine);

            if (match.Success)
            {
                CurrentTestRow[CONST_RESULTTABLE_BULKUPDATEUSERCOUNT] = match.Groups[CONST_RESULTTABLE_BULKUPDATEUSERCOUNT].Value;
                CurrentTestRow[CONST_RESULTTABLE_BULKUSERBUFFERSMIN] = match.Groups[CONST_RESULTTABLE_BULKUSERBUFFERSMIN].Value;
                CurrentTestRow[CONST_RESULTTABLE_BULKUSERBUFFERSMAX] = match.Groups[CONST_RESULTTABLE_BULKUSERBUFFERSMAX].Value;
                CurrentTestRow[CONST_RESULTTABLE_BULKUSERDELAYAFTERCYCLES] = match.Groups[CONST_RESULTTABLE_BULKUSERDELAYAFTERCYCLES].Value;
                CurrentTestRow[CONST_RESULTTABLE_BULKUSERDELAY_MS] = match.Groups[CONST_RESULTTABLE_BULKUSERDELAY_MS].Value;
            }


            if (match.Success)
                return true;


            match = regexTestShrinkUser.Match(CurrentLine);

            if (match.Success)
            {
                CurrentTestRow[CONST_RESULTTABLE_SHRINKMINSHRINKINTERVAL_S] = match.Groups[CONST_RESULTTABLE_SHRINKMINSHRINKINTERVAL_S].Value;
                CurrentTestRow[CONST_RESULTTABLE_SHRINKMAXSHRINKINTERVAL_S] = match.Groups[CONST_RESULTTABLE_SHRINKMAXSHRINKINTERVAL_S].Value;
                CurrentTestRow[CONST_RESULTTABLE_SHRINKMINEXTENDS] = match.Groups[CONST_RESULTTABLE_SHRINKMINEXTENDS].Value;
                CurrentTestRow[CONST_RESULTTABLE_SHRINKMAXEXTENDS] = match.Groups[CONST_RESULTTABLE_SHRINKMAXEXTENDS].Value;
            }


            if (match.Success)
                return true;

            
            match = regexReadAhead.Match(CurrentLine);

            if (match.Success)
            {
                CurrentTestRow[CONST_RESULTTABLE_READAHEADUSERCOUNT] = match.Groups[CONST_RESULTTABLE_READAHEADUSERCOUNT].Value;
                CurrentTestRow[CONST_RESULTTABLE_READAHEADBUFFERSMIN] = match.Groups[CONST_RESULTTABLE_READAHEADBUFFERSMIN].Value;
                CurrentTestRow[CONST_RESULTTABLE_READAHEADBUFFERSMAX] = match.Groups[CONST_RESULTTABLE_READAHEADBUFFERSMAX].Value;
                CurrentTestRow[CONST_RESULTTABLE_READAHEADDELAYAFTERCYCLES] = match.Groups[CONST_RESULTTABLE_READAHEADDELAYAFTERCYCLES].Value;
                CurrentTestRow[CONST_RESULTTABLE_READAHEADDELAY_MS] = match.Groups[CONST_RESULTTABLE_READAHEADDELAY_MS].Value;
            }


            if (match.Success)
                return true;

            #region EndOfTest
            match = regexTestEndTest.Match(CurrentLine);

            if (match.Success)
            {

                if (CurrentTestRow != null)
                {

                    _testInformation.Rows.Add(CurrentTestRow);
                    LocalDriveCounter = 0;
                    CurrentTestRow = null;
                }
            }
            #endregion EndOfTest

            if (match.Success)
                return true;

            
            if (match.Success)
                return true;
            else return false;

        }


        public void ExportResultFileToXML(string ExportFileName)
        {
            if (string.IsNullOrEmpty(ExportFileName))
            {
                HandleMessageEvent(string.Format("ExportFileName cannot be empty."), TraceLevel.Warning);
                return;
            }

            dsResults.WriteXml(ExportFileName);
            HandleMessageEvent(string.Format(CONST_MESSAGE_EXPORT_FILE, ExportFileName), TraceLevel.Info);
            PostProcessEvent(Constants.CONST_ACTION_EXPORTTOXML,null);
        }

        public void ExportResultFileToCsv(string ExportFileName, string Delimiter)
        {
            if (string.IsNullOrEmpty(ExportFileName))
            {
                HandleMessageEvent(string.Format("ExportFileName cannot be empty."), TraceLevel.Warning);
                return;
            }

            if (string.IsNullOrEmpty(Delimiter))
            {
                HandleMessageEvent("Delimiter cannot be empty, please specify a character for separation.", TraceLevel.Warning);
                return;
            }

            string ColumnString = string.Join(Delimiter, (from DataColumn col in dsResults.Tables[0].Columns select col.ColumnName).ToArray()) + Delimiter;
            ColumnString += string.Join(Delimiter, (from DataColumn col in dsResults.Tables[1].Columns select col.ColumnName).ToArray()) + "\r\n";

            string CompleteString = string.Empty;
            string ParentRowString = string.Empty;
            string ChildValues = string.Empty;

            CompleteString = ColumnString;

            foreach (DataRow drParent in dsResults.Tables[0].Rows)
            {
                DataView dv = dsResults.Tables[1].DefaultView;
                dv.RowFilter = "TestId = " + drParent[CONST_RESULTTABLE_TESTID].ToString();

                ChildValues = string.Empty;

                ParentRowString = string.Join(Delimiter, (from DataColumn col in drParent.Table.Columns select drParent[col.ColumnName].ToString()).ToArray());

                foreach (DataRowView drv in dv)
                {
                    ChildValues = string.Format("{0}{1}{2}", ParentRowString, Delimiter + string.Join(Delimiter, (from DataColumn col in drv.DataView.Table.Columns select drv[col.ColumnName].ToString()).ToArray()), "\r\n");
                    CompleteString += ChildValues;
                }
            }

            StreamWriter sw = new StreamWriter(ExportFileName);
            sw.WriteLine(CompleteString);
            sw.Close();

            HandleMessageEvent(string.Format("File successfully written to {0}", ExportFileName),TraceLevel.Info);
            PostProcessEvent(Constants.CONST_ACTION_EXPORTTOCSV, null);
        }


        public static bool PostProcessEvent(string ActionName, string[] parameters)
        {
            return PostProcessEvent(ActionName, parameters, false);
        }

        public static bool PostProcessEvent(string ActionName, string[] parameters, bool OverridePrivacy)
        {
            try
            {
                if (Convert.ToBoolean(CommonHelper.RegistryHelper.ReadRegistrySeetingsCurrentUser("Software\\SQLIOSimParser", "ShareStatistics", false)) || OverridePrivacy)
                {
                    string WebServiceUrl = SQLIOSimParser.Properties.Settings.Default.SoftwareUpdateUrl;
                    WebHelper.TrackAction(WebServiceUrl, ActionName, AssemblyAccessors.AssemblyGuidString, AssemblyAccessors.AssemblyVersion, parameters);
                    return true;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());
            }

            return false;
        }

    }
}
